# -*- coding:utf-8 -*-

# @Time    : 2024/01/16 15:05
# @Author  : yaodong
# @Email   : yaodong@lingxi.ai
# @File    : PlannerSchedule.py
# @Software: LLM_internal

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# 处理定时任务
from apscheduler.schedulers.blocking import BlockingScheduler

from bot.insurance_planner_gpt.qw_server.common import wework_constants
from db.mysql.entity_service import EntitiesDao
from redis_service import RedisMemory

host = "hgprecn-cn-2r42t31q3003-cn-zhangjiakou.hologres.aliyuncs.com"
port = 80
user = "LTAI5tJcbPNJW8Mvd3eJR2JR"
password = "ldWxZWiaejGtxGWTbRAxywNVcNUDG2"
db_name = "screen"

redis_memory = RedisMemory()
scheduler = BlockingScheduler()
entities_dao = EntitiesDao()


@scheduler.scheduled_job('interval', minutes=10)
def redo_find_wechat_code_add_friend():
    need_process_session = redis_memory.smembers(wework_constants.QW_PLANNER_REDIS_KEY_PREFIX + "find_code_error")
    for session_id_cus in need_process_session:
        if session_id_cus:
            session_ids = session_id_cus.split(":")
            session_id = session_ids[0]
            customer_id = session_ids[1]
            add_record = entities_dao.select_add_record_by_id(session_id=session_id)
            if not add_record:
                pass


try:
    # 启动调度器
    scheduler.start()
except (KeyboardInterrupt, SystemExit):
    # 通过键盘中断或系统退出停止调度器
    scheduler.shutdown()
